﻿#include "CBase.h"

CBase::CBase(QString sName, QObject* parent)
	: QObject(parent), m_sName(sName)
{
	m_pParent = NULL;
	this->setParent(parent);
	m_pItem = new QStandardItem(sName);
	m_pItem->setFlags(m_pItem->flags() & ~Qt::ItemIsDragEnabled);  // 移除拖拽能力
	m_pItem->setData(QVariant::fromValue(reinterpret_cast<void*>(this)), Qt::UserRole);
}

CBase::~CBase()
{
	for (auto child : m_pVecChildren) 
	{ 
		delete child; 
	}
}

void CBase::showItem(QTreeView * pTree)
{
	QModelIndex index = m_pItem->index(); // 获取该 item 对应的 QModelIndex
	pTree->expand(index);            // 展开这个节点
	pTree->setCurrentIndex(index);   // 可选：高亮选中
}


